package com.ymatou.iapi.godmch.testcase;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.json.JSONException;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.springframework.context.annotation.Bean;

import com.ymatou.iapi.godmch.parameter.CreateCodeBean;
import com.ymatou.iapi.godmch.parameter.applyAgentBean;
import com.ymatou.iapi.godmch.parameter.approveAgentBean;
import com.ymatou.iapi.godmch.parameter.createIndepMchBean;
import com.ymatou.iapi.godmch.parameter.createagentBean;
import com.ymatou.iapi.godmch.parameter.rejectAgentBean;
import com.ymatou.iapi.godmch.service.CreateCodeCall;
import com.ymatou.iapi.godmch.service.applyAgentCall;
import com.ymatou.iapi.godmch.service.createIndepMchCall;
import com.ymatou.iapi.godmch.service.createagentCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.database.model.agent_type;
import com.ymttest.database.model.country_info;
import com.ymttest.database.model.mch_info;
import com.ymttest.database.model.mch_relation;
import com.ymttest.database.model.godmch.mch_config;
import com.ymttest.database.model.godmch.mch_configExample;
import com.ymttest.database.sqlwapper.godmch.agent_typeWapper;
import com.ymttest.database.sqlwapper.godmch.country_infoWapper;
import com.ymttest.database.sqlwapper.godmch.mch_configWapper;
import com.ymttest.database.sqlwapper.godmch.mch_infoWapper;
import com.ymttest.database.sqlwapper.godmch.mch_relationWapper;
import com.ymttest.utils.TestDataManager;
/**
*申请成为代理商
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_applyAgent{
	private static applyAgentBean bean;
	private static applyAgentCall call;
	createIndepMchBean createBean=new createIndepMchBean();
	createIndepMchCall createCall=new createIndepMchCall();
	
	agent_typeWapper agentTypeWapper=new agent_typeWapper();
	mch_infoWapper infoWapper=new mch_infoWapper();
	country_infoWapper country_infoWapper=new country_infoWapper();
	mch_relationWapper relationWapper=new mch_relationWapper();
	
	mch_configWapper configWapper;
	mch_configExample configExample;
	country_infoWapper countryinfoWapper;
	
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("申请成为代理商");
		
	}

	@Before
	public void caseUp() {
		bean=new applyAgentBean();
		call=new applyAgentCall();
		configExample=new mch_configExample();
		configWapper=new mch_configWapper();
		countryinfoWapper=new country_infoWapper();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(call.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	private void check_verify() throws JSONException, InterruptedException
	{
		Logger.verifyEquals("200", call.getStatusCode1(), "验证status");
		Logger.verifyEquals("请求成功", call.getMessage(), "验证Message");
		
		List<Integer> mchIds_channl=new ArrayList<Integer>();
		mchIds_channl.add(bean.getMchId());
		mch_info  info_channl=infoWapper.selectbyMchIds(mchIds_channl).get(0);
		
		configExample.clear();
		configExample.createCriteria().andMchIdEqualTo(bean.getMchId());
	    mch_config  config_channl=configWapper.selectByExample(configExample).get(0);
	    
		List<Integer> mchIds=new ArrayList<Integer>();
		mchIds.add(call.getAgentId());
		mch_info  info=infoWapper.selectbyMchIds(mchIds).get(0);
		
		configExample.clear();
		configExample.createCriteria().andMchIdEqualTo(call.getAgentId());
	    List<mch_config>  configs=configWapper.selectByExample(configExample);
	    
		Logger.verifyEquals(true, info.getMchId()>0, "验证数据库mch_info新增一条数据");
		Logger.verifyEquals(true, configs.size()==0, "验证数据库mch_config新增0条数据");
		//mch_info
		Logger.verifyEquals(1, info.getAgent(), "验证数据库mch_info中的agent");
		if(createBean.getAgentInvite()==true  && bean.getCountry()!="CHN")
	    	Logger.verifyEquals(1, info.getChannels(), "验证数据库mch_info中的Channels");
		else
			Logger.verifyEquals(0, info.getChannels(), "验证数据库mch_info中的Channels");
		
		Logger.verifyEquals(0, info.getVip(), "验证数据库mch_info中的Vip(如果代理可以邀请代理商，vip=1)");
		
		country_info country_info=country_infoWapper.selectByPrimaryKey(bean.getCountry());
		Logger.verifyEquals(country_info.getCurrency(), info.getCurrency(), "验证数据库mch_info中的Currency");
		Logger.verifyEquals(bean.getCountry(), info.getCountry(), "验证数据库mch_info中的Country");
		Logger.verifyEquals(-2, info.getState(), "验证数据库mch_info中的State=-2待审核");
		
		//Logger.verifyEquals(info_channl.getMchShareType(), info.getMchShareType(), "验证数据库mch_info中的MchShareType");
		//目前有问题，不管分享设置什么，此字段都为4

		//Logger.verifyEquals(createBean.getMchShareType()==3?5:4, info.getMchShareType(), "验证数据库mch_info中的MchShareType");
		//20200509 公共平台目前只能是1或者2
		Logger.verifyEquals(createBean.getMchShareType(), info.getMchShareType(), "验证数据库mch_info中的MchShareType");

		Logger.verifyEquals(2, info.getMchType(), "验证数据库mch_info中的MchType");
		//独立商户 新增 20200326
		Logger.verifyEquals(3, info.getIndepMchFlg(), "验证数据库mch_info中的IndepMchFlg独立商户标识(1:独立商户主商户 2:独立商户供货商 3:独立商户代理商)");
		//mch_relation
		mch_relation relation=relationWapper.selectByPrimaryKey(call.getAgentId(), bean.getMchId()).get(0);
		Logger.verifyEquals(-2, relation.getAgentType(), "验证AgentType");
		Logger.verifyEquals(-2, relation.getAgentModel(), "验证AgentModel");
		Logger.verifyEquals(-2, relation.getState(), "验证state");
		
		//修改 20200409 独立小程序默认是自由支付
		Logger.verifyEquals(5, info.getPayMode(), "验证数据库mch_info中的paymode=5 自有支付");
        //默认开通domesticPayMode=1 盛付通-海鲲科技
        Logger.verifyEquals(1, info.getDomesticPayMode(), "验证数据库mch_info中的DomesticPayMode");
        //商户所在的国家如果不支持本国币种结算，落地USD，否则落地对应国家币种
        country_info countryinfo=countryinfoWapper.selectByPrimaryKey(info.getCountry());
        if(countryinfo.getSupportLocalCurrency().equals(0))
        	Logger.verifyEquals("USD", info.getCurrency(), "验证数据库mch_info中的Currency");
        else
        	Logger.verifyEquals(countryinfo.getCurrency(), info.getCurrency(), "验证数据库mch_info中的Currency");
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_applyAgent_001() {
		//独立商户申请代理，mch_config不会出现代理的数据
		Logger.start(true,"正例-申请成为代理商-默认-代理商可以邀请下级代理，可以发布商品(如果是海外，并且可以发商品，mch_info 中的channels =1，如果不能招下级代理  channels =0)");
		try {
			createBean=GodmchManageCallService.InitCreateIndepMchBean();
			createBean.setAgentPublish(true);
			createBean.setAgentInvite(true);
			createCall=GodmchManageCallService.CreateIndepMchCall(createBean);
			Thread.sleep(5000);//休眠目的是为了创建独立商户，把对应的配置  同步到用户那边，然后用户 拿到配置再创建代理
			bean.setMchId(createCall.getmchId());
			bean.setCountry("USA");
			bean.setMobile("186"+TestDataManager.getRandomIntNum(8));
			bean.setPassword("1111aaaa");
			bean.setAppKey("appsqSeller_"+createCall.getmchId());
			bean.setAppSource(60);
			bean.setTerminalSource(3);
			
			call.setData(bean);
			call.callService();		
			
			check_verify();
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	@Ignore
	public void Tc_applyAgent_001_1() {
		Logger.start(true,"正例-申请成为代理商-默认-代理商不可以邀请下级代理，可以发布商品，此场景有问题，暂不修复");
		try {
			
			createBean=GodmchManageCallService.InitCreateIndepMchBean();
			createBean.setAgentInvite(false);
			createCall=GodmchManageCallService.CreateIndepMchCall(createBean);
			Thread.sleep(5000);//休眠目的是为了创建独立商户，把对应的配置  同步到用户那边，然后用户 拿到配置再创建代理
			bean.setMchId(createCall.getmchId());
			bean.setCountry("USA");
			bean.setMobile("186"+TestDataManager.getRandomIntNum(8));
			bean.setPassword("1111aaaa");
			bean.setAppKey("appsqSeller_"+createCall.getmchId());
			bean.setAppSource(60);
			bean.setTerminalSource(3);
			
			call.setData(bean);
			call.callService();		
			
			check_verify();
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_applyAgent_001_3() {
		Logger.start(true,"正例-申请成为代理商-默认-代理商可以邀请下级代理，可以发布商品(如果是不是海外，并且不可以发商品，mch_info 中的channels =0)");
		try {
			
			createBean=GodmchManageCallService.InitCreateIndepMchBean();
			//createBean.setAgentInvite(true);
			createCall=GodmchManageCallService.CreateIndepMchCall(createBean);
			Thread.sleep(5000);//休眠目的是为了创建独立商户，把对应的配置  同步到用户那边，然后用户 拿到配置再创建代理
			bean.setMchId(createCall.getmchId());
			bean.setCountry("CHN");
			bean.setMobile("186"+TestDataManager.getRandomIntNum(8));
			bean.setPassword("1111aaaa");
			bean.setAppKey("appsqSeller_"+createCall.getmchId());
			bean.setAppSource(60);
			bean.setTerminalSource(3);
			
			call.setData(bean);
			call.callService();		
			
			check_verify();
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}


	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_applyAgent_001_4() {
		Logger.start(true,"正例-申请成为代理商-不同商户的两个代理，手机号码一致,返回正常");
		try {
			
			String mobile="186"+TestDataManager.getRandomIntNum(8);
			createBean=GodmchManageCallService.InitCreateIndepMchBean();
			createCall=GodmchManageCallService.CreateIndepMchCall(createBean);
			Thread.sleep(5000);//休眠目的是为了创建独立商户，把对应的配置  同步到用户那边，然后用户 拿到配置再创建代理
			bean.setMchId(createCall.getmchId());
			bean.setCountry("USA");
			bean.setMobile(mobile);
			bean.setPassword("1111aaaa");
			bean.setAppKey("appsqSeller_"+createCall.getmchId());
			bean.setAppSource(60);
			bean.setTerminalSource(3);
			call.setData(bean);
			call.callService();	
			//第二个商户 申请代理
			createBean=GodmchManageCallService.InitCreateIndepMchBean();
			createBean.setAgentInvite(true);
			createCall=GodmchManageCallService.CreateIndepMchCall(createBean);
			Thread.sleep(5000);//休眠目的是为了创建独立商户，把对应的配置  同步到用户那边，然后用户 拿到配置再创建代理
			bean.setMchId(createCall.getmchId());
			bean.setCountry("USA");
			bean.setMobile(mobile);
			bean.setPassword("1111aaaa");
			bean.setAppKey("appsqSeller_"+createCall.getmchId());
			bean.setAppSource(60);
			bean.setTerminalSource(3);
			call.setData(bean);
			call.callService();		
			
			check_verify();
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_applyAgent_002() {
		Logger.start(true,"正例-申请成为代理商-mchId不存在");
		try {
			bean.setMchId(11111);
			bean.setCountry("USA");
			bean.setMobile("186"+TestDataManager.getRandomIntNum(8));
			bean.setPassword("1111aaaa");
			bean.setAppKey("appsqSeller_"+"11111");
			bean.setAppSource(60);
			bean.setTerminalSource(3);		
			call.setData(bean);
			call.callService();	
			
			Logger.verifyEquals("5000", call.getStatusCode1(), "验证status");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_applyAgent_003() {
		Logger.start(true,"正例-申请成为代理商-mchId为空");
		try {
			bean.setMchId(null);
			bean.setCountry("USA");
			bean.setMobile("186"+TestDataManager.getRandomIntNum(8));
			bean.setPassword("1111aaaa");
			bean.setAppKey("appsqSeller_");
			bean.setAppSource(60);
			bean.setTerminalSource(3);		
			call.setData(bean);
			call.callService();	
			
			Logger.verifyEquals("4001", call.getStatusCode1(), "验证status");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_applyAgent_004() {
		Logger.start(true,"正例-申请成为代理商-country不存在");
		try {
			createIndepMchBean createBean=GodmchManageCallService.InitCreateIndepMchBean();
			createIndepMchCall createCall=GodmchManageCallService.CreateIndepMchCall(createBean);
			Thread.sleep(5000);//休眠目的是为了创建独立商户，把对应的配置  同步到用户那边，然后用户 拿到配置再创建代理
			bean.setMchId(createCall.getmchId());
			bean.setCountry("ada");
			bean.setMobile("186"+TestDataManager.getRandomIntNum(8));
			bean.setPassword("1111aaaa");
			bean.setAppKey("appsqSeller_"+createCall.getmchId());
			bean.setAppSource(60);
			bean.setTerminalSource(3);
			
			call.setData(bean);
			call.callService();		
			
			Logger.verifyEquals("5015", call.getStatusCode1(), "验证status");
			Logger.verifyEquals("国家信息有误", call.getMessage(), "验证Message");		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_applyAgent_005() {
		Logger.start(true,"正例-申请成为代理商-country为空");
		try {
			
			createIndepMchBean createBean=GodmchManageCallService.InitCreateIndepMchBean();
			createIndepMchCall createCall=GodmchManageCallService.CreateIndepMchCall(createBean);
			Thread.sleep(5000);//休眠目的是为了创建独立商户，把对应的配置  同步到用户那边，然后用户 拿到配置再创建代理
			bean.setMchId(createCall.getmchId());
			bean.setCountry(null);
			bean.setMobile("186"+TestDataManager.getRandomIntNum(8));
			bean.setPassword("1111aaaa");
			bean.setAppKey("appsqSeller_"+createCall.getmchId());
			bean.setAppSource(60);
			bean.setTerminalSource(3);
			
			call.setData(bean);
			call.callService();		
			
			Logger.verifyEquals("4001", call.getStatusCode1(), "验证status");
			Logger.verifyEquals(true, call.getMessage().contains("参数异常"), "验证Message");		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_applyAgent_006() {
		Logger.start(true,"正例-申请成为代理商-mobile为空");
		try {
			createIndepMchBean createBean=GodmchManageCallService.InitCreateIndepMchBean();
			createIndepMchCall createCall=GodmchManageCallService.CreateIndepMchCall(createBean);
			Thread.sleep(5000);//休眠目的是为了创建独立商户，把对应的配置  同步到用户那边，然后用户 拿到配置再创建代理
			bean.setMchId(createCall.getmchId());
			bean.setCountry("USA");
			bean.setMobile("");
			bean.setPassword("1111aaaa");
			bean.setAppKey("appsqSeller_"+createCall.getmchId());
			bean.setAppSource(60);
			bean.setTerminalSource(3);
			
			call.setData(bean);
			call.callService();		
			
			Logger.verifyEquals("4001", call.getStatusCode1(), "验证status");
			Logger.verifyEquals(true, call.getMessage().contains("参数异常"), "验证Message");				
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_applyAgent_007() {
		Logger.start(true,"正例-申请成为代理商-password为空");
		try {
			createIndepMchBean createBean=GodmchManageCallService.InitCreateIndepMchBean();
			createIndepMchCall createCall=GodmchManageCallService.CreateIndepMchCall(createBean);
			Thread.sleep(5000);//休眠目的是为了创建独立商户，把对应的配置  同步到用户那边，然后用户 拿到配置再创建代理
			bean.setMchId(createCall.getmchId());
			bean.setCountry("USA");
			bean.setMobile("186"+TestDataManager.getRandomIntNum(8));
			bean.setPassword("");
			bean.setAppKey("appsqSeller_"+createCall.getmchId());
			bean.setAppSource(60);
			bean.setTerminalSource(3);
			
			call.setData(bean);
			call.callService();		
			
			Logger.verifyEquals("4001", call.getStatusCode1(), "验证status");
			Logger.verifyEquals(true, call.getMessage().contains("参数异常"), "验证Message");		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_applyAgent_007_1() {
		Logger.start(true,"正例-申请成为代理商-password密码格式错误,6-9位数字和英文字母组合");
		try {
			createIndepMchBean createBean=GodmchManageCallService.InitCreateIndepMchBean();
			createIndepMchCall createCall=GodmchManageCallService.CreateIndepMchCall(createBean);
			Thread.sleep(5000);//休眠目的是为了创建独立商户，把对应的配置  同步到用户那边，然后用户 拿到配置再创建代理
			bean.setMchId(createCall.getmchId());
			bean.setCountry("USA");
			bean.setMobile("186"+TestDataManager.getRandomIntNum(8));
			bean.setPassword("111");
			bean.setAppKey("appsqSeller_"+createCall.getmchId());
			bean.setAppSource(60);
			bean.setTerminalSource(3);
			
			call.setData(bean);
			call.callService();		
			
			Logger.verifyEquals("5000", call.getStatusCode1(), "验证status");
			Logger.verifyEquals(true, call.getMessage().contains("密码格式错误,6-9位数字和英文字母组合"), "验证Message");		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_applyAgent_008() {
		Logger.start(true,"正例-申请成为代理商-appSource为空");
		try {
			createIndepMchBean createBean=GodmchManageCallService.InitCreateIndepMchBean();
			createIndepMchCall createCall=GodmchManageCallService.CreateIndepMchCall(createBean);
			Thread.sleep(5000);//休眠目的是为了创建独立商户，把对应的配置  同步到用户那边，然后用户 拿到配置再创建代理
			bean.setMchId(createCall.getmchId());
			bean.setCountry("USA");
			bean.setMobile("186"+TestDataManager.getRandomIntNum(8));
			bean.setPassword("121231");
			bean.setAppKey("appsqSeller_"+createCall.getmchId());
			bean.setAppSource(null);
			bean.setTerminalSource(3);
			
			call.setData(bean);
			call.callService();		
			
			Logger.verifyEquals("4001", call.getStatusCode1(), "验证status");
			Logger.verifyEquals(true, call.getMessage().contains("参数异常"), "验证Message");		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	@Ignore
	public void Tc_applyAgent_009() {
		Logger.start(true,"正例-申请成为代理商-appSource不存在,目前有60,61,62,63,64");
		try {
			createIndepMchBean createBean=GodmchManageCallService.InitCreateIndepMchBean();
			createIndepMchCall createCall=GodmchManageCallService.CreateIndepMchCall(createBean);
			Thread.sleep(5000);//休眠目的是为了创建独立商户，把对应的配置  同步到用户那边，然后用户 拿到配置再创建代理
			bean.setMchId(createCall.getmchId());
			bean.setCountry("USA");
			bean.setMobile("186"+TestDataManager.getRandomIntNum(8));
			bean.setPassword("121231");
			bean.setAppKey("appsqSeller_"+createCall.getmchId());
			bean.setAppSource(66);
			bean.setTerminalSource(3);
			
			call.setData(bean);
			call.callService();		
			
			org.junit.Assert.fail();			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_applyAgent_010() {
		Logger.start(true,"正例-申请成为代理商-terminalSource为空");
		try {
			createIndepMchBean createBean=GodmchManageCallService.InitCreateIndepMchBean();
			createIndepMchCall createCall=GodmchManageCallService.CreateIndepMchCall(createBean);
			Thread.sleep(5000);//休眠目的是为了创建独立商户，把对应的配置  同步到用户那边，然后用户 拿到配置再创建代理
			bean.setMchId(createCall.getmchId());
			bean.setCountry("USA");
			bean.setMobile("186"+TestDataManager.getRandomIntNum(8));
			bean.setPassword("1111aaaa");
			bean.setAppKey("appsqSeller_"+createCall.getmchId());
			bean.setAppSource(60);
			bean.setTerminalSource(null);
			
			call.setData(bean);
			call.callService();		
			
			Logger.verifyEquals("4001", call.getStatusCode1(), "验证status");
			Logger.verifyEquals(true, call.getMessage().contains("参数异常"), "验证Message");			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_applyAgent_011() {
		Logger.start(true,"正例-申请成为代理商-terminalSource不存在,目前有0,1,2,3,4");
		try {
			createIndepMchBean createBean=GodmchManageCallService.InitCreateIndepMchBean();
			createIndepMchCall createCall=GodmchManageCallService.CreateIndepMchCall(createBean);
			Thread.sleep(5000);//休眠目的是为了创建独立商户，把对应的配置  同步到用户那边，然后用户 拿到配置再创建代理
			bean.setMchId(createCall.getmchId());
			bean.setCountry("USA");
			bean.setMobile("186"+TestDataManager.getRandomIntNum(8));
			bean.setPassword("111aaaa");
			bean.setAppKey("appsqSeller_"+createCall.getmchId());
			bean.setAppSource(66);
			bean.setTerminalSource(23123);
			
			call.setData(bean);
			call.callService();		
			
			Logger.verifyEquals("5000", call.getStatusCode1(), "验证status");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_applyAgent_012() {
		//Logger.start(true,"正例-申请成为代理商-独立商户分享类型3：独立小程序，数据库应该是5：独立小程序继承版(如果商户是小程序，代理如果也是小程序，代理小程序的相关配置没有设置)");
		Logger.start(true,"正例-申请成为代理商-独立商户分享类型3：独立小程序，数据库应该是3：独立小程序(20200508修改 供货商、代理商与主商户一致)");
		try {
			//独立商户主商户和供货商运营后台界面  分享类型只能设置1公共小程序 2公共H5     
			//主商户的代理 运营后台界面 都可以设置 1公共小程序 2公共H5  3  独立小程序 4独立H5
			createBean=GodmchManageCallService.InitCreateIndepMchBean();
			createBean.setMchShareType(3);
			createCall=GodmchManageCallService.CreateIndepMchCall(createBean);
			Thread.sleep(5000);//休眠目的是为了创建独立商户，把对应的配置  同步到用户那边，然后用户 拿到配置再创建代理
			bean.setMchId(createCall.getmchId());
			bean.setCountry("USA");
			bean.setMobile("186"+TestDataManager.getRandomIntNum(8));
			bean.setPassword("1111aaaa");
			bean.setAppKey("appsqSeller_"+createCall.getmchId());
			bean.setAppSource(60);
			bean.setTerminalSource(3);
			
			call.setData(bean);
			call.callService();		
			
			List<Integer> mchIds=new ArrayList<Integer>();
			mchIds.add(call.getAgentId());
			mch_info  info=infoWapper.selectbyMchIds(mchIds).get(0);
			
			Logger.verifyEquals(3, info.getMchShareType(), "验证数据库mch_info中的MchShareType");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_applyAgent_013() {
		//Logger.start(true,"正例-申请成为代理商-独立商户分享类型4：独立H5，数据库应该是5：独立小程序继承版(如果商户是小程序，代理如果也是小程序，代理小程序的相关配置没有设置)");
		Logger.start(true,"正例-申请成为代理商-独立商户分享类型4：独立H5，数据库应该是4：独立H5(20200508修改 供货商、代理商与主商户一致)");
		try {
			
			createBean=GodmchManageCallService.InitCreateIndepMchBean();
			createBean.setMchShareType(4);
			createCall=GodmchManageCallService.CreateIndepMchCall(createBean);
			Thread.sleep(5000);//休眠目的是为了创建独立商户，把对应的配置  同步到用户那边，然后用户 拿到配置再创建代理
			bean.setMchId(createCall.getmchId());
			bean.setCountry("USA");
			bean.setMobile("186"+TestDataManager.getRandomIntNum(8));
			bean.setPassword("1111aaaa");
			bean.setAppKey("appsqSeller_"+createCall.getmchId());
			bean.setAppSource(60);
			bean.setTerminalSource(3);
			
			call.setData(bean);
			call.callService();		
			
			List<Integer> mchIds=new ArrayList<Integer>();
			mchIds.add(call.getAgentId());
			mch_info  info=infoWapper.selectbyMchIds(mchIds).get(0);
			
			Logger.verifyEquals(4, info.getMchShareType(), "验证数据库mch_info中的MchShareType");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_applyAgent_014() {
		Logger.start(true,"正例-申请成为代理商-独立商户分享类型1：公共小程序，数据库应该是1：公共小程序");
		try {
			//独立商户主商户和供货商 运营后台界面分享类型只能设置1公共小程序 2公共H5     
			//主商户的代理 运营后台界面 都可以设置 1公共小程序 2公共H5  3  独立小程序 4独立H5
			createBean=GodmchManageCallService.InitCreateIndepMchBean();
			createBean.setMchShareType(1);
			createCall=GodmchManageCallService.CreateIndepMchCall(createBean);
			Thread.sleep(5000);//休眠目的是为了创建独立商户，把对应的配置  同步到用户那边，然后用户 拿到配置再创建代理
			bean.setMchId(createCall.getmchId());
			bean.setCountry("USA");
			bean.setMobile("186"+TestDataManager.getRandomIntNum(8));
			bean.setPassword("1111aaaa");
			bean.setAppKey("appsqSeller_"+createCall.getmchId());
			bean.setAppSource(60);
			bean.setTerminalSource(3);
			
			call.setData(bean);
			call.callService();		
			
			List<Integer> mchIds=new ArrayList<Integer>();
			mchIds.add(call.getAgentId());
			mch_info  info=infoWapper.selectbyMchIds(mchIds).get(0);
			
			Logger.verifyEquals(1, info.getMchShareType(), "验证数据库mch_info中的MchShareType");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_applyAgent_015() {
		Logger.start(true,"正例-申请成为代理商-独立商户分享类型2：公共H5，数据库应该是2：公共H5");
		try {
			//独立商户主商户和供货商 运营后台界面分享类型只能设置1公共小程序 2公共H5     
			//主商户的代理 运营后台界面 都可以设置 1公共小程序 2公共H5  3  独立小程序 4独立H5
			createBean=GodmchManageCallService.InitCreateIndepMchBean();
			createBean.setMchShareType(2);
			createCall=GodmchManageCallService.CreateIndepMchCall(createBean);
			Thread.sleep(5000);//休眠目的是为了创建独立商户，把对应的配置  同步到用户那边，然后用户 拿到配置再创建代理
			bean.setMchId(createCall.getmchId());
			bean.setCountry("USA");
			bean.setMobile("186"+TestDataManager.getRandomIntNum(8));
			bean.setPassword("1111aaaa");
			bean.setAppKey("appsqSeller_"+createCall.getmchId());
			bean.setAppSource(60);
			bean.setTerminalSource(3);
			
			call.setData(bean);
			call.callService();		
			
			List<Integer> mchIds=new ArrayList<Integer>();
			mchIds.add(call.getAgentId());
			mch_info  info=infoWapper.selectbyMchIds(mchIds).get(0);
			
			Logger.verifyEquals(2, info.getMchShareType(), "验证数据库mch_info中的MchShareType");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_applyAgent_016() {
		Logger.start(true,"正例-申请成为代理商-使用邀请码(如果有邀请码，代理直接审核通过)");
		try {
			createIndepMchBean createBean=GodmchManageCallService.InitCreateIndepMchBean();
			createIndepMchCall createCall=GodmchManageCallService.CreateIndepMchCall(createBean);
			//邀请码
			CreateCodeBean createCodeBean=GodmchManageCallService.InitcreateCodeBeanForAgent(createCall.getmchId(), true);
			CreateCodeCall createCodeCall=GodmchManageCallService.createCodeCall(createCodeBean);
			Thread.sleep(5000);//休眠目的是为了创建独立商户，把对应的配置  同步到用户那边，然后用户 拿到配置再创建代理
			bean.setMchId(createCall.getmchId());
			bean.setCountry("USA");
			bean.setMobile("186"+TestDataManager.getRandomIntNum(8));
			bean.setPassword("111aaaa");
			bean.setAppKey("appsqSeller_"+createCall.getmchId());
			bean.setAppSource(60);
			bean.setTerminalSource(3);
			
			bean.setInviteCode(createCodeCall.getCode());
			call.setData(bean);
			call.callService();		
			
			Logger.verifyEquals("200", call.getStatusCode1(), "验证status");
			List<Integer> mchIds=new ArrayList<Integer>();
			mchIds.add(call.getAgentId());
			mch_info  info=infoWapper.selectbyMchIds(mchIds).get(0);
			Logger.verifyEquals(0, info.getState(), "验证数据库mch_info中的State=0审核通过");
			
			//查询代理类型
			Map<String,Object> map=new HashMap();
			map.put("mchId", bean.getMchId());
			List<agent_type> list=agentTypeWapper.selectby(map);
			//mch_relation
			mch_relation relation=relationWapper.selectByPrimaryKey(call.getAgentId(), bean.getMchId()).get(0);
			Logger.verifyEquals(list.get(0).getAgentType(), relation.getAgentType(), "验证AgentType");
			Logger.verifyEquals(1, relation.getAgentModel(), "验证AgentModel");
			Logger.verifyEquals(0, relation.getState(), "验证state");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_applyAgent_017() {
		Logger.start(true,"正例-申请成为代理商-代理再申请代理-使用邀请码(如果有邀请码，代理直接审核通过)");
		try {
            ///////////////////// 主商户招代理////////////////////////
			createIndepMchBean createBean=GodmchManageCallService.InitCreateIndepMchBean();
			createIndepMchCall createCall=GodmchManageCallService.CreateIndepMchCall(createBean);
			//独立商户邀请码
			CreateCodeBean createCodeBean=GodmchManageCallService.InitcreateCodeBeanForAgent(createCall.getmchId(), true);
			CreateCodeCall createCodeCall=GodmchManageCallService.createCodeCall(createCodeBean);
			Thread.sleep(5000);
			bean=GodmchManageCallService.InitApplyAgentBean();
			bean.setMchId(createCall.getmchId());
			bean.setAppKey("appsqSeller_"+bean.getMchId());
			bean.setInviteCode(createCodeCall.getCode());
			call=GodmchManageCallService.ApplyAgentCall(bean);
			
			Logger.comment("MchId1:"+createCodeBean.getMchId());
			Logger.comment("Agent1:"+call.getAgentId());
			
			//查询代理类型
			Map<String,Object> map=new HashMap();
			map.put("mchId", createCodeBean.getMchId());
			List<agent_type> list=agentTypeWapper.selectby(map);
			//mch_relation
			mch_relation relation=relationWapper.selectByPrimaryKey(call.getAgentId(), bean.getMchId()).get(0);
			Logger.verifyEquals(list.get(0).getAgentType(), relation.getAgentType(), "验证AgentType");
			Logger.verifyEquals(1, relation.getAgentModel(), "验证AgentModel");
			Logger.verifyEquals(0, relation.getState(), "验证state");
			 /////////////////////// 代理招代理////////////////////////
			//代理申请代理
		    createCodeBean=GodmchManageCallService.InitcreateCodeBeanForAgent(call.getAgentId(),true);
			createCodeCall=GodmchManageCallService.createCodeCall(createCodeBean);
			Thread.sleep(5000);
			bean=GodmchManageCallService.InitApplyAgentBean();
			//bean.setMchId(call.getAgentId());
			bean.setMchId(createCall.getmchId());
			bean.setAppKey("appsqSeller_"+createCall.getmchId());
			bean.setInviteCode(createCodeCall.getCode());
			call=GodmchManageCallService.ApplyAgentCall(bean);
			
			Logger.comment("MchId2:"+createCodeBean.getMchId());
			Logger.comment("Agent2:"+call.getAgentId());
			
			Logger.verifyEquals("200", call.getStatusCode1(), "验证status");
			List<Integer> mchIds=new ArrayList<Integer>();
			mchIds.add(call.getAgentId());
			mch_info  info=infoWapper.selectbyMchIds(mchIds).get(0);
			Logger.verifyEquals(0, info.getState(), "验证数据库mch_info中的State=0审核通过");
			
			//查询代理类型
			map=new HashMap();
			map.put("mchId", createCodeBean.getMchId());
			list=agentTypeWapper.selectby(map);
			//mch_relation
			relation=relationWapper.selectByPrimaryKey(call.getAgentId(),createCodeBean.getMchId()).get(0);
			Logger.verifyEquals(list.get(0).getAgentType(), relation.getAgentType(), "验证AgentType");
			Logger.verifyEquals(1, relation.getAgentModel(), "验证AgentModel");
			Logger.verifyEquals(0, relation.getState(), "验证state");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_applyAgent_018() {
		Logger.start(true,"正例-申请成为分销代理商-使用邀请码-分销小店返佣(如果有邀请码，代理直接审核通过)");
		try {
			createIndepMchBean createBean=GodmchManageCallService.InitCreateIndepMchBean();
			createIndepMchCall createCall=GodmchManageCallService.CreateIndepMchCall(createBean);
			//邀请码
			CreateCodeBean createCodeBean=GodmchManageCallService.InitcreateCodeBeanForAgent(createCall.getmchId(), false);
			// 创建代理类型
			createagentBean createagentBean = GodmchManageCallService.InitCreateAgentTypeBean(createCall.getmchId());
			createagentBean.setAgentMode(2);//小店
			createagentBean.setRebateRate(new BigDecimal(2));//返佣
			createagentBean.setRebateRate(new BigDecimal(2));
			createagentCall createagentcall = GodmchManageCallService.CreateAgentTypeCall(createagentBean);
			
			//查询类型
			agent_typeWapper agentTypewapper = new agent_typeWapper();
			Map<String, Object> map = new HashMap();
			map.put("mchId", createCall.getmchId());
			List<agent_type> agenttypeList = agentTypewapper.selectby(map);
			createCodeBean.setRoleType(agenttypeList.get(2).getAgentType());
			
			CreateCodeCall createCodeCall=GodmchManageCallService.createCodeCall(createCodeBean);
			
			Thread.sleep(5000);//休眠目的是为了创建独立商户，把对应的配置  同步到用户那边，然后用户 拿到配置再创建代理
			bean.setMchId(createCall.getmchId());
			bean.setCountry("USA");
			bean.setMobile("186"+TestDataManager.getRandomIntNum(8));
			bean.setPassword("111aaaa");
			bean.setAppKey("appsqSeller_"+createCall.getmchId());
			bean.setAppSource(60);
			bean.setTerminalSource(3);
			
			bean.setInviteCode(createCodeCall.getCode());
			call.setData(bean);
			call.callService();		
			
			Logger.verifyEquals("200", call.getStatusCode1(), "验证status");
			List<Integer> mchIds=new ArrayList<Integer>();
			mchIds.add(call.getAgentId());
			mch_info  info=infoWapper.selectbyMchIds(mchIds).get(0);
			Logger.verifyEquals(0, info.getState(), "验证数据库mch_info中的State=0审核通过");
			//纯代理
			Logger.verifyEquals(1, info.getAgent(), "验证数据库mch_info中的Agent=0");
			Logger.verifyEquals(0, info.getChannels(), "验证数据库mch_info中的Channels=0");
			
			//查询代理类型
			 map=new HashMap();
			map.put("mchId", bean.getMchId());
			List<agent_type> list=agentTypeWapper.selectby(map);
			//mch_relation
			mch_relation relation=relationWapper.selectByPrimaryKey(call.getAgentId(), bean.getMchId()).get(0);
			Logger.verifyEquals(list.get(2).getAgentType(), relation.getAgentType(), "验证AgentType");
			Logger.verifyEquals(2, relation.getAgentModel(), "验证AgentModel");
			Logger.verifyEquals(0, relation.getState(), "验证state");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_applyAgent_019() {
		Logger.start(true,"正例-申请成为代理商-审核通过代理再招代理-不使用邀请码");
		try {
			///////////////主商户////////
			createIndepMchBean createBean=GodmchManageCallService.InitCreateIndepMchBean();
			createIndepMchCall createCall=GodmchManageCallService.CreateIndepMchCall(createBean);
			//邀请码
			CreateCodeBean createCodeBean=GodmchManageCallService.InitcreateCodeBeanForAgent(createCall.getmchId(), false);
			
			//查询类型
			agent_typeWapper agentTypewapper = new agent_typeWapper();
			Map<String, Object> map = new HashMap();
			map.put("mchId", createCall.getmchId());
			List<agent_type> agenttypeList = agentTypewapper.selectby(map);
			createCodeBean.setRoleType(agenttypeList.get(1).getAgentType());
			CreateCodeCall createCodeCall=GodmchManageCallService.createCodeCall(createCodeBean);
            ///////////////////主商户代理 、审核通过 ///////////////////
			applyAgentCall applyAgentCall=GodmchManageCallService.applyAndapproveAgent(createCall.getmchId());
			////////////代理 招代理 待审核 /////////
			bean.setMchId(applyAgentCall.getAgentId());
			bean.setCountry("USA");
			bean.setMobile("186" + TestDataManager.getRandomIntNum(8));
			bean.setPassword("1111aaaa");
			bean.setAppSource(60);
			bean.setTerminalSource(0);
			bean.setAppKey("appsqSeller_" + createCall.getmchId());
			
			call.setData(bean);
			call.callService();
			
			Logger.verifyEquals("200", call.getStatusCode1(), "验证status");
			Logger.verifyEquals("请求成功", call.getMessage(), "验证Message");
			
			Logger.comment("##############  验证mch_info");
			List<Integer> mchIds=new ArrayList<Integer>();
			mchIds.add(call.getAgentId());
			mch_info  info=infoWapper.selectbyMchIds(mchIds).get(0);
			//mch_info
			Logger.verifyEquals(1, info.getAgent(), "验证数据库mch_info中的agent");
			if(createBean.getAgentInvite()==true  && bean.getCountry()!="CHN")
		    	Logger.verifyEquals(1, info.getChannels(), "验证数据库mch_info中的Channels");
			else
				Logger.verifyEquals(0, info.getChannels(), "验证数据库mch_info中的Channels");
			
			Logger.verifyEquals(0, info.getVip(), "验证数据库mch_info中的Vip(如果代理可以邀请代理商，vip=1)");
			
			country_info country_info=country_infoWapper.selectByPrimaryKey(bean.getCountry());
			Logger.verifyEquals(country_info.getCurrency(), info.getCurrency(), "验证数据库mch_info中的Currency");
			Logger.verifyEquals(bean.getCountry(), info.getCountry(), "验证数据库mch_info中的Country");
			Logger.verifyEquals(-2, info.getState(), "验证数据库mch_info中的State=-2待审核");
			
			//mch_relation
			Logger.comment("##############  验证mch_relation");
			mch_relation relation=relationWapper.selectByPrimaryKey(call.getAgentId(), bean.getMchId()).get(0);
			Logger.verifyEquals(-2, relation.getAgentType(), "验证AgentType");
			Logger.verifyEquals(-2, relation.getAgentModel(), "验证AgentModel");
			Logger.verifyEquals(-2, relation.getState(), "验证state");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}